#include "blockqueue.hpp"
#include "task.hpp"
#include <iostream>
#include <pthread.h>
#include <unistd.h>

void* consumer(void* args)
{
    BlockQueue<task_t>*bq=static_cast<BlockQueue<task_t>*>(args);
    while (true)
    {
        sleep(3);
        task_t t =bq->Pop();
        cout<<"消费一个任务"<<endl;
        t();
    }
}
void* producer(void* args)
{
    BlockQueue<task_t>*bq=static_cast<BlockQueue<task_t>*>(args);
    while(true)
    {
        bq->Equeue(download);
        cout<<"生产一个任务"<<endl;

    }
}

int main()
{
    BlockQueue<task_t>*bq=new BlockQueue<task_t>();
    pthread_t c[2],p[3];
    pthread_create(c,nullptr,consumer,bq);
    pthread_create(c+1,nullptr,consumer,bq);
    pthread_create(p,nullptr,producer,bq);
    pthread_create(p+1,nullptr,producer,bq);
    pthread_create(p+2,nullptr,producer,bq);

    pthread_join(c[0],nullptr);
    pthread_join(c[1],nullptr);
    pthread_join(p[0],nullptr);
    pthread_join(p[1],nullptr);
    pthread_join(p[2],nullptr);
    return 0;
}